package com.syauto.sm;

import java.util.ArrayList;

import com.syauto.entity.JingPinClass;
import com.syauto.user.OrderInfo;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class AftermarketChoose extends TabActivity{

	public static ArrayList<JingPinClass> listEntity;
	public static String CHUAN_SONG_WANG_DIAN;
	TabHost tabHost;
	
	RadioButton radbtn0;
	RadioButton radbtn1;
	RadioButton radbtn2;
	
	Intent intentJinp;
	Intent intentTaoc;
	Intent intentJinpOk;
	
	Button btnReturn;
	Button btnSave;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.order_aftermarket);
		listEntity = new ArrayList<JingPinClass>();
		listEntity.addAll(OrderInfo.jingPinglist);
		
		radbtn0 = (RadioButton)this.findViewById(R.id.radio0);
		radbtn0.setOnCheckedChangeListener(new RadioButton_Checked());
		radbtn1 = (RadioButton)this.findViewById(R.id.radio1);
		radbtn1.setOnCheckedChangeListener(new RadioButton_Checked());
		radbtn2 = (RadioButton)this.findViewById(R.id.radio2);
		radbtn2.setOnCheckedChangeListener(new RadioButton_Checked());
		
		intentJinp = new Intent(this,JingPinSelectedActivity.class);
		intentTaoc = new Intent(this,JingPinTaoCanActivity.class);
		intentJinpOk = new Intent(this,JingPinOkActivity.class);
		
		btnReturn = (Button) this.findViewById(R.id.btnBack);
		btnReturn.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View paramView) {
				AftermarketChoose.this.finish();
			}
			
		});
		btnSave = (Button) this.findViewById(R.id.btnSubmit);
		btnSave.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View paramView) {
				OrderInfo.jingPinglist = listEntity;
			}
			
		});
		
		setupIntent();
	}
	
	private void setupIntent() {
		this.tabHost = this.getTabHost();
		TabHost localTabHost = this.tabHost;
		localTabHost.addTab(localTabHost.newTabSpec("xz").setIndicator("xz").setContent(intentJinp));
		localTabHost.addTab(localTabHost.newTabSpec("tc").setIndicator("tc").setContent(intentTaoc));
		localTabHost.addTab(localTabHost.newTabSpec("ok").setIndicator("ok").setContent(intentJinpOk));
	}
	
	class RadioButton_Checked implements OnCheckedChangeListener
	{

		@Override
		public void onCheckedChanged(CompoundButton paramCpdBtn, boolean paramBool) {
			if (!paramBool)
				return;
			
			switch (paramCpdBtn.getId()) {
			case R.id.radio0:
				tabHost.setCurrentTabByTag("xz");
				break;
			case R.id.radio1:
				tabHost.setCurrentTabByTag("tc");
				break;
			case R.id.radio2:
				tabHost.setCurrentTabByTag("ok");
				break;
			}
		}
	}
	

}
